Skip to content

[feat/#212] 마이페이지 커스텀 alert 구현#213

Open
SeungWon1125 wants to merge 4 commits intodevelopfrom
feat/#212-myPageCustomAlert
Open

[feat/#212] 마이페이지 커스텀 alert 구현#213
SeungWon1125 wants to merge 4 commits intodevelopfrom
feat/#212-myPageCustomAlert

Conversation

@SeungWon1125
Copy link
Copy Markdown
Collaborator

🔗 연결된 이슈

📄 작업 내용

  • 로그아웃, 회원탈퇴 커스텀 Alert을 구현했어요
  • gif엔 안 나오지만, 기존에 구현했던 로그아웃과 회원탈퇴 기능과 연결해 놓았습니다!
구현 내용 iPhone 13 mini iPhone 16 pro
커스텀 Alert

💻 주요 코드 설명

Builder패턴 again

  • alert창을 띄울 때 alertTitle이나 buttonTitle 등등 다 init으로 받는 건 가독성도 별로 좋지 않고, 효율성이 떨어진다고 판단하여 builder패턴을 도입해 보았습니다ㅏ
  • 아직 이 customAlert창이 로그아웃, 회원탈퇴에서만 사용되어 크게 이점은 없는 거 같긴 한데,
  • 나중에 더 추가되면 선택적 파라미터 처리나, 추가 UI 구현 (함수로 추가)가 더 쉬워질 거 같슴돠~!
// AlertBuilder.swift

private var alertTitle: String?
private var confirmAction: AlertAction?
private var cancelAction: AlertAction?
...
func setTitle(_ alertTitle: String) -> AlertBuilder {
    self.alertTitle = alertTitle
    return self
}

func setConfirmAction(_ text: String, action: (() -> Void)? = nil) -> AlertBuilder {
    self.confirmAction = AlertAction(text: text, action: action)
    return self
}

func setCancelAction(_ text: String, action: (() -> Void)? = nil) -> AlertBuilder {
    self.cancelAction = AlertAction(text: text, action: action)
    return self
}

@discardableResult
func build() -> Self {
    alertViewController.modalPresentationStyle = .overFullScreen
    alertViewController.modalTransitionStyle = .crossDissolve
    
    alertViewController.alertTitle = alertTitle
    alertViewController.confirmAction = confirmAction
    alertViewController.cancelAction = cancelAction
    
    baseViewController.present(alertViewController, animated: true)
    return self
}
...
  • 요렇게 alertTitle, 그리고 action들을 붙여주는 함수들과 마지막으로 build 하는 함수를 구현했어요

// MyAccountViewController.swift
...
rootView.logoutButton
    .tapPublisher
    .sink { [weak self] in
        guard let self else { return }
        
        AlertBuilder(viewController: self)
            .setTitle("로그아웃 하시겠습니까?")
            .setConfirmAction("확인") {
                self.logoutButtonDidTapSubject.send()
            }
            .setCancelAction("취소")
            .build()
    }
    .store(in: cancelBag)
  • 사용하는 곳에서 이렇게 사용하면 됩니다!

📚 참고자료

https://www.hohyeonmoon.com/blog/custom-alert-builder-pattern

👀 기타 더 이야기해볼 점

  • 지금 우선 AlertBuilder.swift 파일 안에 builder 객체와 UI(RoomieAlertViewController) 모두 작성한 상태인데, 분리를 하는 게 맞을지 한 파일에서 관리하는 게 맞을지 고민입니다!
  • 느낌상 Alert에 관한 코드라 한 파일에세ㅓ 관리하는 게 더 좋아보이긴 하는데,, 잘 모르겠네요

@SeungWon1125 SeungWon1125 self-assigned this Jul 22, 2025
@SeungWon1125 SeungWon1125 added 🛠️ feat 새로운 기능 구현 시 사용 🍞 seungwon labels Jul 22, 2025
@SeungWon1125 SeungWon1125 linked an issue Jul 22, 2025 that may be closed by this pull request
1 task
Copy link
Copy Markdown
Collaborator

@maeng-kim maeng-kim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

몬가 분리하는 게 좋을 것 같기두 하구요,, 근데 승원이 말대로 alert관련이니까 한 파일도 좋을 것 같기두 하구요 ,,
근데 어케 이걸 builder로 할 생각을 하셨나요 진짜 천재


import UIKit

final class AlertBuilder {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

승원이 ㅈㅉ 천재냐 !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ feat 새로운 기능 구현 시 사용 🍞 seungwon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 마이페이지 커스텀 alert창 구현

2 participants